package com.qk.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qk.common.PageResult;
import com.qk.entity.Activity;
import com.qk.mapper.ActivityMapper;
import com.qk.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageResult<Activity> selectPage(Integer channel, Integer type, Integer status, Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        List<Activity> activityList = activityMapper.selectPage(channel,type,status);

        PageInfo<Activity> pageInfo = new PageInfo<>(activityList);
        return new PageResult<>(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public void insert(Activity activity) {
        activity.setCreateTime(LocalDateTime.now());
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.insert(activity);
    }

    @Override
    public Activity selectById(Integer id) {
        Activity activity = activityMapper.selectById(id);
        return activity;
    }

    @Override
    public void updateActivity(Activity activity) {
        activity.setUpdateTime(LocalDateTime.now());
        activityMapper.updateActivity(activity);
    }

    @Override
    public void delectById(Integer id) {
        activityMapper.delectById();
    }

    @Override
    public List<Activity> selectByType(Integer type) {
        return activityMapper.selectByType(type);
    }

//    @Override
//    public List<Activity> list() {
//        return activityMapper.list();
//    }
}
